var EnumBody = require('./../Enum/EnumBody');
var EnumPlane = require('./../Enum/EnumPlane');
var BasePlane = require('./../Plane/BasePlane');
var BaseBody = require('./../BaseBody');
var EnumProp = require('./../Enum/EnumProp');
cc.Class(
{
    extends: BaseBody,
    properties:
    {
        audioClip:
        {
            type: cc.AudioClip,
            default: null,
            displayName: '被吸收声音'
        },

        enumProp:
        {
            default: EnumProp.NONE,
            type: EnumProp,
            displayName: '道具类型'
        }
    },
    onLoad()
    {
        this.setEnumBody(EnumBody.PROP);
    },

    onCollisionEnter: function(other)
    {
        var body = this._super(other);
        if (null == body)
        {
            return;
        }

        var bodyType = body.getEnumBody();
        if (EnumBody.PLANE == bodyType)
        {
            var planeCtr = other.getComponent(BasePlane);
            if (null == planeCtr)
            {
                cc.error('飞机没带管理脚本');
                return;
            }
            var enumPlane = planeCtr.getEnumPlane();
            if (EnumPlane.MY == enumPlane)
            {
                cc.log('被吃掉');
                this.playbAudio();
            }
        }
    },

    /**
     * 播放挂载音效
     */
    playbAudio()
    {
        if (!!this.audioClip)
        {
            cc.audioEngine.play(this.audioClip, false, 1);
        }
    },

    /**
     * 设置道具类型
     */
    setEnumProp(_enumProp)
    {
        this.enumProp = _enumProp;
    },

    /**
     * 获得道具类型
     */
    getEnumProp()
    {
        return this.enumProp;
    }
});